import os

class DynamicDirNode:
    @classmethod
    def INPUT_TYPES(cls):
        return {
            "required": {
                "dir_path": ("STRING", {"default": "/", "multiline": False}),
            }
        }

    RETURN_TYPES = ("CUSTOM",)
    RETURN_NAMES = ("dynamic_entries",)
    FUNCTION = "list_dir"
    CATEGORY = "AI训练/path_manager"

    def list_dir(self, dir_path):
        entries = []
        try:
            for entry in os.listdir(dir_path):
                full_path = os.path.join(dir_path, entry)
                entry_type = "dir" if os.path.isdir(full_path) else "file"
                entries.append({
                    "name": entry,
                    "path": full_path,
                    "type": entry_type
                })
        except Exception as e:
            print(f"读取目录失败: {e}")
        return ({"entries": entries},)

# 节点注册
NODE_CLASS_MAPPINGS = {
    "DynamicDirNode": DynamicDirNode,
}
NODE_DISPLAY_NAME_MAPPINGS = {
    "DynamicDirNode": "动态目录节点",
} 